function [geoMap] = a_9_getGeoMapping(Minput, GEO_VARS, geoCodes, entityId, entityLabels)
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	% This function takes as input a table where one column contains an id called entityIdVarName (not necessarily sorted in the right order),
	% and other columns that give geographic mapping of the id into geographic entities (CodeInsee, CantonId, etc.)
	% The ids are assumed to be unique.
	% We have all the ids in entityLabels sorted in the right order.
	% The function returns a cell array tha maps, for each geographic level, the index of the geographic entity that corresponds to each id (in the right order).
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Inputs:
	% Minput:        table
	% GEO_VARS:      cell(NumGeoVars,1) of strings --> ({'CodeInsee', 'CantonId', 'ARR_ID', 'DEP'})
	% geoCodes:      cell(NumGeoVars,1):
	%	{gg}:			cell(NumGeoValues,1) of strings
	% entityId:      string (e.g. 'CarId', 'UserId', ...)
	% entityLabels:  (=carLabels,...)
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Outputs:
    % geoMap:		cell(NumGeoVars,1)
    %  {gg}:            NumEntities x 1 --> gives index between 1 and K (index of corresponding geographic entity)
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	NumGeoVars = length(GEO_VARS);
    geoMap = cell(1,NumGeoVars);
    NumEntities = length(entityLabels);
	for gidx = 1:NumGeoVars
		GEO_VAR = GEO_VARS{gidx};
		
		entityIds = table2array(Minput(:,entityId));
		geoIds    = table2cell(Minput(:,GEO_VAR));
		
		[~,entityIdxes] = ismember(entityIds, entityLabels);
		[~,geoIdxes]    = ismember(geoIds, geoCodes{gidx});
		
		geoMap_gg = zeros(NumEntities,1);
		geoMap_gg(entityIdxes) = geoIdxes;
		geoMap{gidx} = geoMap_gg;
		
		% Test to ensure consistency
		T1a = table(entityLabels); T1a.Properties.VariableNames = {entityId};
		T1b = table(geoCodes{gidx}(geoMap{gidx})); T1b.Properties.VariableNames = {GEO_VAR};
		T1 = [T1a T1b];
		T1 = T1(entityIdxes,:);
		if ~isequal(T1, Minput(:,{entityId, GEO_VAR})); error('Error somehow'); end; clear T1;
		
		% Clean up
		clear geoMap_gg geoPart_idx;
	end
end
